package br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo;
import br.edu.ufcg.lsd.wbis.ui.client.ui.AbstractMainPanel;
import br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.admin.CenterPanel;
import br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.admin.leftmenu.MenuPanel;
import br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.admin.uppermenu.UpperPanel;
import br.edu.ufcg.lsd.wbis.ui.client.ui.management.InfoManager;
import br.edu.ufcg.lsd.wbis.ui.client.ui.management.PanelManager;

import com.gwtext.client.core.Margins;
import com.gwtext.client.core.RegionPosition;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.BorderLayoutData;

/**
 * @author Renato Miceli
 */
public abstract class LoggedPanel extends AbstractMainPanel {

	private final String userLogin;

	public LoggedPanel(PanelManager panelManager) {

		this.userLogin = panelManager.getInfoManager().getInfo().getLogin();

		this.setLayout(new BorderLayout());

		InfoManager<UserInfo> infoManager = panelManager.getInfoManager();
		CenterPanel centerPanel = new CenterPanel(infoManager);
		this.add(centerPanel, new BorderLayoutData(RegionPosition.CENTER));

		this.add(new UpperPanel(panelManager, centerPanel), new BorderLayoutData(RegionPosition.NORTH));

		final BorderLayoutData bottomData = new BorderLayoutData(RegionPosition.SOUTH);
		bottomData.setMinSize(100);
		bottomData.setMaxSize(200);
		bottomData.setMargins(new Margins(0, 0, 0, 0));
		bottomData.setSplit(true);
		this.add(new MainBottomPanel(), bottomData);

		final BorderLayoutData leftData = new BorderLayoutData(RegionPosition.WEST);
		leftData.setSplit(true);
		leftData.setMinSize(175);
		leftData.setMaxSize(400);
		leftData.setMargins(new Margins(0, 5, 0, 0));
		this.add(new MenuPanel(centerPanel, infoManager), leftData);
	}

	/**
	 * {@inheritDoc}
	 */
	public String getPageTitle() {
		return "Web-Based Inventory System -- Logged as " + this.userLogin;
	}
	
}
